package code.rocky.chapter05;

import java.util.*;

public class Suggest77 {
    public static void main(String[] args) {
        demo01();
        demo02();
        demo03();
    }

    private static void demo01() {
        int tagCloudNum = 10;
        List<String> tagClouds = initList();
        Random random = new Random();
        for (int i = 0; i < tagClouds.size(); i++) {
            int randomPosition = random.nextInt(tagCloudNum);
            String temp = tagClouds.get(i);
            tagClouds.set(i, tagClouds.get(randomPosition));
            tagClouds.set(randomPosition, temp);
        }
        System.out.println("====start=====");
        for (String tagCloud : tagClouds) {
            System.out.print(tagCloud + " ");
        }
        System.out.println("====end=====");
    }

    private static List<String> initList() {
        return Arrays.asList("1","2","3","4","5","6","7","8","9","10");
    }

    private static void demo02() {
        int tagCloudNum = 10;
        List<String> tagClouds = initList();
        Random random = new Random();
        for (int i = 0; i < tagClouds.size(); i++) {
            int randomPosition = random.nextInt(tagCloudNum);
            Collections.swap(tagClouds, i, randomPosition);
        }
        System.out.println("====start=====");
        for (String tagCloud : tagClouds) {
            System.out.print(tagCloud + " ");
        }
        System.out.println("====end=====");
    }

    private static void demo03() {
        int tagCloudNum = 10;
        List<String> tagClouds = initList();
        Random random = new Random();
        Collections.shuffle(tagClouds);
        System.out.println("====start=====");
        for (String tagCloud : tagClouds) {
            System.out.print(tagCloud + " ");
        }
        System.out.println("====end=====");
    }
}
